//
//  WBTabBarViewController.swift
//  weibo
//
//  Created by chenguanglei on 16/11/25.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class WBTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
       addChildViewController()

        
        let tabBar = WBTabBar()
        
        setValue(tabBar, forKey: "tabBar")
        
        
        weak var weakSelf = self
        
        tabBar.closure = {
        
            print("点击加号按钮")
            
            WBPopView.show(target: weakSelf!)
        
        }
        
    }
    
    
    
    private func addChildViewController() {
        
        addChildViewController(WBHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(WBMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(WBFindViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(WBMineViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    private func addChildViewController(_ childController: UIViewController, title:String, imageName:String) {
        
        
        //设置tabBar渲染的三种方法
//        tabBar.tintColor = UIColor.blue
//        
//        UITabBar.appearance().tintColor = UIColor.green
//        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_highlighted")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
   
        childController.title = title
        
        //设置选中文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: UIControlState.selected)
        
        //设置文字大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName : UIFont.systemFont(ofSize: 12)], for: UIControlState.normal)
        
        
        childController.tabBarItem.image = UIImage(named:imageName)
        
        let nav = UINavigationController.init(rootViewController: childController)
        
        addChildViewController(nav)
        
    }
    

    
}
